package com.caszx.chargingpile.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.app.base.app.BaseTopBarDelayActivity;
import com.app.utils.CacheTools;
import com.app.utils.DiskUser;
import com.app.view.ShapeTextView;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.eventbus.EventBusAction;

import de.greenrobot.event.EventBus;

public class SettingActivity extends BaseTopBarDelayActivity implements View.OnClickListener {


    private ShapeTextView btn_signout;
    private TextView txt_cache_size;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);


    }


    @Override
    protected void findView() {

        btn_signout = (ShapeTextView) findViewById(R.id.btn_signout);
        txt_cache_size = (TextView) findViewById(R.id.txt_cache_size);
        findViewById(R.id.btn_clear_cache).setOnClickListener(this);
        btn_signout.setOnClickListener(this);

        String token = DiskUser.getStringValueByKey(this,"token");
        if(TextUtils.isEmpty(token)){
            btn_signout.setVisibility(View.GONE);
        }
        txt_cache_size.setText(CacheTools.getHttpCacheSize(this));

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_clear_cache:
                if (!txt_cache_size.getText().toString().equals("0KB")) {
                    txt_cache_size.setText("0KB");
                    CacheTools.clearAppCache(getApplicationContext());
                }

                break;

            case R.id.btn_signout:
                DiskUser.setSignOut(this);
                EventBus.getDefault().post(EventBusAction.ACTION_SING_OUT);
                finish();
                break;
        }
    }
}
